home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 15 / CU Amiga Magazine's Super CD-ROM 15 (1997)(EMAP Images)(GB)[!][issue 1997-10].iso / CUCD / Graphics / Ghostscript / source / gs_init.ps < prev    next >
Encoding:
Text File  |  1997-06-22  |  44.6 KB  |  1,452 lines

  1. %    Copyright (C) 1989, 1996, 1997 Aladdin Enterprises.  All rights reserved.
  2. % This file is part of Aladdin Ghostscript.
  3. % Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  4. % or distributor accepts any responsibility for the consequences of using it,
  5. % or for whether it serves any particular purpose or works at all, unless he
  6. % or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  7. % License (the "License") for full details.
  8. % Every copy of Aladdin Ghostscript must include a copy of the License,
  9. % normally in a plain ASCII text file named PUBLIC.  The License grants you
  10. % the right to copy, modify and redistribute Aladdin Ghostscript, but only
  11. % under certain conditions described in the License.  Among other things, the
  12. % License requires that the copyright notice and this notice be preserved on
  13. % all copies.
  14.  
  15. % Initialization file for the interpreter.
  16. % When this is run, systemdict is still writable.
  17.  
  18. % Comment lines of the form
  19. %    %% Replace <n> <file(s)>
  20. % indicate places where the next <n> lines should be replaced by
  21. % the contents of <file(s)>, when creating a single merged init file.
  22.  
  23. % The interpreter can call out to PostScript code.  All procedures
  24. % called in this way, and no other procedures defined in these
  25. % initialization files, have names that begin with %, e.g.,
  26. % (%Type1BuildChar) cvn.
  27.  
  28. % Check the interpreter revision.  NOTE: the interpreter code requires
  29. % that the first non-comment token in this file be an integer.
  30. 501        % **** re-release of 1997-6-22
  31. dup revision ne
  32.  { (gs: Interpreter revision \() print revision 10 string cvs print
  33.    (\) does not match gs_init.ps revision \() print 10 string cvs print
  34.    (\).\n) print flush null 1 .quit
  35.  }
  36. if pop
  37.  
  38. % Acquire userdict, and set its length if necessary.
  39. /userdict where
  40.  { pop userdict maxlength 0 eq }
  41.  { true }
  42. ifelse
  43.  {        % userdict wasn't already set up by iinit.c.
  44.    /userdict
  45.    currentdict dup 200 .setmaxlength        % userdict
  46.    systemdict begin def        % can't use 'put', userdict is local
  47.  }
  48.  { systemdict begin
  49.  }
  50. ifelse
  51.  
  52. % Define dummy local/global operators if needed.
  53. systemdict /.setglobal known
  54.  { true .setglobal
  55.  }
  56.  { /.setglobal { pop } bind def
  57.    /.currentglobal { false } bind def
  58.    /.gcheck { pop false } bind def
  59.  }
  60. ifelse
  61.  
  62. % Define .languagelevel if needed.
  63. systemdict /.languagelevel known not { /.languagelevel 1 def } if
  64.  
  65. % Optionally choose a default paper size other than U.S. letter.
  66. % (a4) /PAPERSIZE where { pop pop } { /PAPERSIZE exch def } ifelse
  67.  
  68. % Turn on array packing for the rest of initialization.
  69. true setpacking
  70.  
  71. % Define the old MS-DOS EOF character as a no-op.
  72. % This is a hack to get around the absurd habit of MS-DOS editors
  73. % of adding an EOF character at the end of the file.
  74. <1a> cvn { } def
  75.  
  76. % Acquire the debugging flags.
  77. currentdict /DEBUG known   /DEBUG exch def
  78.   /VMDEBUG
  79.     DEBUG {{print mark
  80.             systemdict /level2dict known
  81.          { .currentglobal dup false .setglobal vmstatus
  82.            true .setglobal vmstatus 3 -1 roll pop
  83.            6 -2 roll pop .setglobal
  84.          }
  85.          { vmstatus 3 -1 roll pop
  86.          }
  87.         ifelse usertime 16#fffff and counttomark
  88.           { ( ) print (           ) cvs print }
  89.         repeat pop
  90.         ( ) print systemdict length (    ) cvs print
  91.         ( ) print countdictstack (  ) cvs print
  92.         ( <) print count (  ) cvs print (>\n) print flush
  93.       }}
  94.       {{pop
  95.       }}
  96.      ifelse
  97.   def
  98.  
  99. currentdict /BATCH known   /BATCH exch def
  100. currentdict /DELAYBIND known   /DELAYBIND exch def
  101. currentdict /DISKFONTS known   /DISKFONTS exch def
  102. currentdict /ESTACKPRINT known   /ESTACKPRINT exch def
  103. currentdict /FAKEFONTS known   /FAKEFONTS exch def
  104. currentdict /FIXEDMEDIA known   /FIXEDMEDIA exch def
  105. currentdict /FIXEDRESOLUTION known   /FIXEDRESOLUTION exch def
  106. currentdict /LOCALFONTS known   /LOCALFONTS exch def
  107. currentdict /NOBIND known   /NOBIND exch def
  108. /.bind /bind load def
  109. NOBIND { /bind { } def } if
  110. currentdict /NOCACHE known   /NOCACHE exch def
  111. currentdict /NOCIE known   /NOCIE exch def
  112. currentdict /NODISPLAY known   not /DISPLAYING exch def
  113. currentdict /NOFONTMAP known   /NOFONTMAP exch def
  114. currentdict /NOFONTPATH known   /NOFONTPATH exch def
  115. currentdict /NOGC known   /NOGC exch def
  116. currentdict /NOPAUSE known   /NOPAUSE exch def
  117. currentdict /NOPLATFONTS known   /NOPLATFONTS exch def
  118. currentdict /NOPROMPT known   /NOPROMPT exch def
  119. % The default value of ORIENT1 is true, not false.
  120. currentdict /ORIENT1 known not { /ORIENT1 true def } if
  121. currentdict /OSTACKPRINT known   /OSTACKPRINT exch def
  122. currentdict /OUTPUTFILE known    % obsolete
  123.  { /OutputFile /OUTPUTFILE load def
  124.    currentdict /OUTPUTFILE .undef
  125.  } if
  126. currentdict /QUIET known   /QUIET exch def
  127. currentdict /SAFER known   /SAFER exch def
  128. currentdict /SHORTERRORS known   /SHORTERRORS exch def
  129. currentdict /WRITESYSTEMDICT known   /WRITESYSTEMDICT exch def
  130.  
  131. % Acquire environment variables.
  132. currentdict /DEVICE known not
  133.  { (GS_DEVICE) getenv { /DEVICE exch def } if } if
  134.  
  135. (START) VMDEBUG
  136.  
  137. % Open the standard files, so they will be open at the outermost save level.
  138. (%stdin) (r) file pop
  139. (%stdout) (w) file pop
  140. (%stderr) (w) file pop
  141.  
  142. % Define a procedure for skipping over an unneeded section of code.
  143. % This avoids allocating space for the skipped procedures.
  144. % We can't use readline, because that imposes a line length limit.
  145. /.skipeof    % <string> .skipeof -
  146.  { currentfile exch 1 exch .subfiledecode flushfile
  147.  } bind def
  148.  
  149. % If we're delaying binding, remember everything that needs to be bound later.
  150. DELAYBIND NOBIND not and
  151.  { .currentglobal false .setglobal
  152.    userdict /.delaybind 1500 array put
  153.    .setglobal
  154.    userdict /.delaycount 0 put
  155.     % When we've done the delayed bind, we want to stop saving.
  156.     % Detect this by the disappearance of .delaybind.
  157.    /bind
  158.     { userdict /.delaybind .knownget
  159.        { .delaycount 2 index put
  160.          userdict /.delaycount .delaycount 1 add put
  161.        }
  162.        { .bind
  163.        }
  164.       ifelse
  165.     } bind def
  166.  } if
  167.  
  168. % Define procedures to assist users who don't read the documentation.
  169. userdict begin
  170. /help
  171.  { (Enter PostScript commands.  '(filename) run' runs a file, 'quit' exits.\n)
  172.    print flush
  173.  } bind def
  174. /? /help load def
  175. end
  176.  
  177. % Define =string, which is used by some PostScript programs even though
  178. % it isn't documented anywhere.
  179. % Put it in userdict so that each context can have its own copy.
  180. userdict /=string 256 string put
  181.  
  182. % Print the greeting.
  183.  
  184. /printgreeting
  185.  { mark
  186.    product (Ghostscript) search
  187.     { pop pop pop
  188.       (This software comes with NO WARRANTY: see the file PUBLIC for details.\n)
  189.     }
  190.     { pop
  191.     }
  192.    ifelse
  193.    (\n) copyright
  194.    (\)\n) revisiondate 100 mod (-)
  195.    revisiondate 100 idiv 100 mod (-)
  196.    revisiondate 10000 idiv ( \()
  197.    revision 10 mod
  198.    revision 100 mod dup 0 ne { 10 idiv } { pop } ifelse (.)
  199.    revision 100 idiv ( )
  200.    product
  201.    counttomark
  202.     { (%stdout) (w) file exch false .writecvp
  203.     } repeat pop
  204.  } bind def
  205.  
  206. QUIET not { printgreeting flush } if
  207.  
  208. % Define a special version of def for making operator procedures.
  209. /odef        % <name> <proc> odef -
  210.  { 1 index exch .makeoperator def
  211.  } .bind def
  212.  
  213. %**************** BACKWARD COMPATIBILITY
  214. /getdeviceprops
  215.  { null .getdeviceparams
  216.  } bind odef
  217. /.putdeviceprops
  218.  { null true counttomark 1 add 3 roll .putdeviceparams
  219.    dup type /booleantype ne
  220.     { dup mark eq { /unknown /rangecheck } if
  221.       counttomark 4 add 1 roll cleartomark pop pop pop
  222.       /.putdeviceprops load exch signalerror
  223.     }
  224.    if
  225.  } bind odef
  226. /max { .max } bind def
  227. /min { .min } bind def
  228. /.currentfilladjust { .currentfilladjust2 pop } bind odef
  229. /.setfilladjust { dup .setfilladjust2 } bind odef
  230. /.writecvs { false .writecvp } bind odef
  231.  
  232. % Define predefined procedures substituting for operators,
  233. % in alphabetical order.
  234.  
  235. userdict /#copies 1 put
  236. % Adobe implementations don't accept /[ or /], so we don't either.
  237. ([) cvn
  238.     /mark load def
  239. (]) cvn
  240.     {counttomark array astore exch pop} odef
  241. /abs    {dup 0 lt {neg} if} odef
  242. % .beginpage is redefined if setpagedevice is present.
  243. /.beginpage { } odef
  244. /copypage
  245.     { 1 .endpage
  246.        { .currentnumcopies false .outputpage
  247.          (>>copypage, press <return> to continue<<\n) .confirm
  248.        }
  249.       if .beginpage
  250.     } odef
  251. % .currentnumcopies is redefined in Level 2.
  252. /.currentnumcopies { #copies } odef
  253. /setcolorscreen where { pop        % not in all Level 1 configurations
  254.    /currentcolorscreen
  255.     { .currenthalftone
  256.        { { 60 exch 0 exch 3 copy 6 copy }    % halftone - not possible
  257.          { 3 copy 6 copy }            % screen
  258.          { }                % colorscreen
  259.        }
  260.       exch get exec
  261.     } odef
  262. } if
  263. /currentscreen
  264.     { .currenthalftone
  265.        { { 60 exch 0 exch }            % halftone - not possible
  266.          { }                % screen
  267.          { 12 3 roll 9 { pop } repeat }    % colorscreen
  268.        }
  269.       exch get exec
  270.     } odef
  271. /.echo /echo load def
  272. userdict /.echo.mode true put
  273. /echo    {dup /.echo.mode exch store .echo} odef
  274. /eexec
  275.     { 55665 //filterdict /eexecDecode get exec
  276.       cvx //systemdict begin stopped
  277.         % Only pop systemdict if it is still the top element,
  278.         % because this is apparently what Adobe interpreters do.
  279.       currentdict //systemdict eq { end } if
  280.       { stop } if
  281.     } odef
  282. % .endpage is redefined if setpagedevice is present.
  283. /.endpage { 2 ne } odef
  284. % erasepage mustn't use gsave/grestore, because we call it before
  285. % the graphics state stack has been fully initialized.
  286. /erasepage
  287.     { /currentcolor where
  288.        { pop currentcolor currentcolorspace { setcolorspace setcolor } }
  289.        { /currentcmykcolor where
  290.           { pop currentcmykcolor { setcmykcolor } }
  291.           { currentrgbcolor { setrgbcolor } }
  292.          ifelse
  293.        }
  294.       ifelse 1 setgray .fillpage exec
  295.     } odef
  296. /executive
  297.     { { prompt
  298.          { (%statementedit) (r) file } stopped
  299.          { pop pop $error /errorname get /undefinedfilename eq
  300.         { .clearerror exit } if        % EOF
  301.            handleerror null        % ioerror??
  302.          }
  303.         if
  304.         cvx { .runexec } execute
  305.       } loop
  306.     } odef
  307. /filter
  308.     { //filterdict 1 index .knownget
  309.        { exch pop exec }
  310.        { /filter load /undefined signalerror }
  311.       ifelse
  312.     } odef
  313. /handleerror
  314.     { //systemdict /errordict get /handleerror get exec } bind def
  315. /identmatrix [1.0 0.0 0.0 1.0 0.0 0.0] readonly def
  316. /identmatrix
  317.     { //identmatrix exch copy } odef
  318. /languagelevel 1 def        % gs_lev2.ps may change this
  319. /makeimagedevice { false makewordimagedevice } odef
  320. /matrix    { 6 array identmatrix } odef
  321. /pathbbox
  322.     { false { .pathbbox } stopped
  323.        { pop /pathbbox load $error /errorname get signalerror } if
  324.     } odef
  325. /prompt    { flush flushpage
  326.       (GS) print
  327.       count 0 ne { (<) print count =only } if
  328.       (>) print flush
  329.     } bind def
  330. /pstack    { 0 1 count 3 sub { index == } for } bind def
  331. /putdeviceprops
  332.     { .putdeviceprops { erasepage } if } odef
  333. /quit    { /quit load 0 .quit } odef
  334. /run    { dup type /filetype ne { (r) file } if
  335.         % We must close the file when execution terminates,
  336.         % regardless of the state of the stack,
  337.         % and then propagate an error, if any.
  338.       cvx .runexec
  339.     } odef
  340. % Execute a file.
  341. % Level 2 uses 2 .stop to clear the e-stack for a successful startjob:
  342. % we detect that here, since we need to handle this even if we start out
  343. % without job control in effect.
  344. %
  345. % What we push on the e-stack is the following to be executed in this order:
  346. %    <lit-file|fileproc> .runexec1 <lit-file|fileproc> .runexec2
  347. /.runexec1 {        % <file|fileproc> .runexec1 -
  348.   dup type /filetype ne { cvx exec } if
  349.   cvx null 2 .stopped
  350.     % If we got back here from a startjob, just keep going.
  351.     % startjob replaces the null on the o-stack with a procedure
  352.     % to be executed when we get back here.
  353.   dup null ne { exec true } { pop false } ifelse
  354. } bind def
  355. /.runexec2 {        % <continue> <file|fileproc> .runexec2 -
  356.   exch {
  357.     .runexec
  358.   } {
  359.     dup type /filetype ne { cvx exec } if
  360.     closefile
  361.   } ifelse
  362. } bind def
  363. /.runexec {        % <file|fileproc> .runexec -
  364.   cvlit /.runexec1 cvx 1 index /.runexec2 cvx 4 .execn
  365. } bind def
  366. /setdevice
  367.     { .setdevice { erasepage } if } odef
  368. /setlinecap {
  369.     dup 2 gt { /setlinecap load /rangecheck signalerror } if
  370.     .setlinecap
  371. } odef
  372. /setlinejoin {
  373.     dup 2 gt { /setlinejoin load /rangecheck signalerror } if
  374.     .setlinejoin
  375. } odef
  376. /showpage
  377.     { 0 .endpage .doneshowpage
  378.        { .currentnumcopies true .outputpage
  379.          (>>showpage, press <return> to continue<<\n) .confirm
  380.          erasepage
  381.        }
  382.       if initgraphics .beginpage
  383.     } odef
  384. % Code output by Adobe Illustrator relies on the fact that
  385. % `stack' is a procedure, not an operator!!!
  386. /stack    { 0 1 count 3 sub { index = } for } bind def
  387. /start    { BATCH { null 0 .quit } { executive } ifelse } def
  388. % Internal uses of stopped that aren't going to do a stop if an error occurs
  389. % should use .internalstopped to avoid setting newerror et al.
  390. /.internalstopped { null 1 .stopped null ne } bind def
  391. /store    {    % Don't alter operands before completing.
  392.       1 index where { 2 index 2 index put pop pop } { def } ifelse
  393.     } odef
  394. % When running in Level 1 mode, this interpreter is supposed to be
  395. % compatible with PostScript "version" 54.0 (I think).
  396. /version (54.0) def
  397.  
  398. % internaldict is defined in systemdict, but is allocated in local VM.
  399. systemdict /internaldict .knownget not { 0 } if type /operatortype ne
  400.  { .currentglobal false .setglobal
  401.    //systemdict /internaldict known not { /internaldict 5 dict def } if
  402.    /internaldict
  403.     [ /dup load 1183615869 /eq load
  404.        [ /pop load internaldict ] cvx
  405.        [ /internaldict /cvx load /invalidaccess /signalerror cvx ] cvx
  406.       /ifelse load
  407.     ] cvx bind odef
  408.    .setglobal
  409.  } if
  410.  
  411. % Define some additional built-in procedures (beyond the ones defined by
  412. % the PostScript Language Reference Manual).
  413. % Warning: these are not guaranteed to stay the same from one release
  414. % to the next!
  415. /concatstrings
  416.     { exch dup length 2 index length add string    % str2 str1 new
  417.       dup dup 4 2 roll copy        % str2 new new new1
  418.       length 4 -1 roll putinterval
  419.     } bind def
  420. /copyarray
  421.     { dup length array copy } bind def
  422. % Copy a dictionary per the Level 2 spec even in Level 1.
  423. /.copydict        % <fromdict> <todict> .copydict <todict>
  424.     { dup 3 -1 roll { put dup } forall pop } bind def
  425. /copystring
  426.     { dup length string copy } bind def
  427. /finddevice
  428.     { //systemdict /devicedict get exch get
  429.       dup 1 get null eq
  430.        {        % This is the first request for this type of device.
  431.             % Create a default instance now.
  432.             % Stack: [proto null]
  433.          .currentglobal true .setglobal exch
  434.          dup dup 0 get copydevice 1 exch put
  435.          exch .setglobal
  436.        }
  437.       if 1 get
  438.     } bind def
  439. /.growdictlength    % get size for growing a dictionary
  440.     { length 3 mul 2 idiv 1 add
  441.     } bind def
  442. /.growdict        % grow a dictionary
  443.     { dup .growdictlength .setmaxlength
  444.     } bind def
  445. /.growput        % put, grow the dictionary if needed
  446.     { 2 index length 3 index maxlength eq
  447.        { 3 copy pop known not { 2 index .growdict } if
  448.        } if
  449.       put
  450.     } bind def
  451. /.packtomark
  452.     { counttomark packedarray exch pop } bind def
  453. /ppstack
  454.     { 0 1 count 3 sub { index === } for } bind def
  455. /runlibfile
  456.     {        % We don't want to bind 'run' into this procedure,
  457.             % since run may get redefined.
  458.       findlibfile
  459.        { exch pop //systemdict /run get exec }
  460.        { /undefinedfilename signalerror }
  461.       ifelse
  462.     } bind def
  463. /selectdevice
  464.     { finddevice setdevice .setdefaultscreen } bind def
  465. /signalerror        % <object> <errorname> signalerror -
  466.     { //systemdict /errordict get exch get exec } bind def
  467.  
  468. % Define the =[only] procedures.  Also define =print,
  469. % which is used by some PostScript programs even though
  470. % it isn't documented anywhere.
  471. /write=only
  472.     { { .writecvs } .internalstopped
  473.        { pop (--nostringval--) writestring
  474.        }
  475.       if
  476.     } bind def
  477. /write=
  478.     { 1 index exch write=only (\n) writestring
  479.     } bind def
  480. /=only    { (%stdout) (w) file exch write=only } bind def
  481. /=    { =only (\n) print } bind def
  482. /=print    /=only load def
  483. % Temporarily define == as = for the sake of runlibfile0.
  484. /== /= load def
  485.  
  486. % Define procedures for getting and setting the current device resolution.
  487.  
  488. /gsgetdeviceprop    % <device> <propname> gsgetdeviceprop <value>
  489.  { 2 copy mark exch null .dicttomark .getdeviceparams
  490.    dup mark eq        % if true, not found
  491.     { pop dup /undefined signalerror }
  492.     { 5 1 roll pop pop pop pop }
  493.    ifelse
  494.  } bind def
  495. /gscurrentresolution    % - gscurrentresolution <[xres yres]>
  496.  { currentdevice /HWResolution gsgetdeviceprop
  497.  } bind def
  498. /gssetresolution    % <[xres yres]> gssetresolution -
  499.  { 2 array astore mark exch /HWResolution exch
  500.    currentdevice copydevice putdeviceprops setdevice
  501.  } bind def
  502.  
  503. % Define auxiliary procedures needed for the above.
  504. /shellarguments        % -> shell_arguments true (or) false
  505.     { /ARGUMENTS where
  506.        { /ARGUMENTS get dup type /arraytype eq
  507.           { aload pop /ARGUMENTS null store true }
  508.           { pop false }
  509.          ifelse }
  510.        { false } ifelse
  511.     } bind def
  512. /.confirm
  513.     { DISPLAYING NOPAUSE not and
  514.        {    % Print a message (unless NOPROMPT is true)
  515.         % and wait for the user to type something.
  516.         % If the user just types a newline, flush it.
  517.          NOPROMPT { pop } { print flush } ifelse
  518.          .echo.mode false echo
  519.          (%stdin) (r) file dup read
  520.           { dup (\n) 0 get eq { pop pop } { unread } ifelse }
  521.           { pop }
  522.          ifelse echo
  523.        }
  524.        { pop
  525.        }
  526.       ifelse
  527.     } bind def
  528.  
  529. % Define the procedure used by .runfile, .runstdin and .runstring
  530. % for executing user input.
  531. % This is called with a procedure or executable file on the operand stack.
  532. /.execute {        % <obj> .execute <stopped>
  533.   stopped $error /newerror get and
  534.    { handleerror flush true } { false } ifelse
  535. } bind def
  536. /execute {        % <obj> execute -
  537.   .execute pop
  538. } odef
  539. % Define an execute analogue of runlibfile0.
  540. /execute0 {        % <obj> execute0 -
  541.   .execute { /execute0 cvx 1 .quit } if
  542. } bind def
  543. % Define the procedure that the C code uses for running files
  544. % named on the command line.
  545. /.runfile {
  546.   { runlibfile } execute
  547. } def
  548. % Define the procedure that the C code uses for running piped input.
  549. % We don't use the obvious { (%stdin) run }, because we want the file to be
  550. % reopened if a startjob does a restore.
  551. /.runstdin {
  552.   { { (%stdin) (r) file cvx } .runexec } execute0
  553. } bind def
  554. % Define the procedure that the C code uses for running commands
  555. % given on the command line with -c.  We turn the string into a file so that
  556. % .runexec can do the right thing with a startjob.
  557. /.runstring {
  558.   .currentglobal exch true .setglobal
  559.   0 () .subfiledecode
  560.   exch .setglobal cvx .runexec
  561. } bind def
  562. % Define the procedure that the C code uses to set up for executing
  563. % a string that may be received in pieces.
  564. /.runstringbegin {
  565.   .currentglobal true .setglobal
  566.   { .needinput } bind 0 () .subfiledecode
  567.   exch .setglobal cvx { .runexec } execute
  568. } bind def
  569.  
  570. % Define a special version of runlibfile that aborts on errors.
  571. /runlibfile0
  572.     { cvlit dup /.currentfilename exch def
  573.        { findlibfile not { stop } if }
  574.       stopped
  575.        { (Can't find \(or open\) initialization file ) print
  576.          .currentfilename == flush /runlibfile0 cvx 1 .quit
  577.        } if
  578.       exch pop cvx stopped
  579.        { (While reading ) print .currentfilename print (:\n) print flush
  580.          handleerror /runlibfile0 1 .quit
  581.        } if
  582.     } bind def
  583. % Temporarily substitute it for the real runlibfile.
  584. /.runlibfile /runlibfile load def
  585. /runlibfile /runlibfile0 load def
  586.  
  587. % Create the error handling machinery.
  588. % Define the standard error handlers.
  589. % The interpreter has created the ErrorNames array.
  590. /.unstoppederrorhandler    % <command> <errorname> .unstoppederrorhandler -
  591.  {    % This is the handler that gets used for recursive errors,
  592.     % or errors outside the scope of a 'stopped'.
  593.    2 copy SHORTERRORS
  594.     { (%%[ Error: ) print =only flush
  595.       (; OffendingCommand: ) print =only ( ]%%\n) print
  596.     }
  597.     { (Unrecoverable error: ) print =only flush
  598.       ( in ) print = flush
  599.       count 2 gt
  600.        { (Operand stack:\n  ) print
  601.      2 1 count 3 sub { (  ) print index =only flush } for
  602.      (\n) print flush
  603.        } if
  604.     }
  605.    ifelse
  606.    -1 0 1 //ErrorNames length 1 sub
  607.     { dup //ErrorNames exch get 3 index eq
  608.        { not exch pop exit } { pop } ifelse
  609.     }
  610.    for exch pop .quit
  611.  } bind def
  612. /.errorhandler        % <command> <errorname> .errorhandler -
  613.   {        % Detect an internal 'stopped'.
  614.     1 .instopped { null eq { pop pop stop } if } if
  615.     $error /.inerror get 1 .instopped { pop } { pop true } ifelse
  616.      { .unstoppederrorhandler
  617.      } if    % detect error recursion
  618.     $error /globalmode .currentglobal false .setglobal put
  619.     $error /.inerror true put
  620.     $error /newerror true put
  621.     $error exch /errorname exch put
  622.     $error exch /command exch put
  623.     $error /recordstacks get $error /errorname get /VMerror ne and
  624.      {        % Attempt to store the stack contents atomically.
  625.        count array astore dup $error /ostack 4 -1 roll
  626.        countexecstack array execstack $error /estack 3 -1 roll
  627.        countdictstack array dictstack $error /dstack 3 -1 roll
  628.        put put put aload pop
  629.      }
  630.      { $error /dstack .undef
  631.        $error /estack .undef
  632.        $error /ostack .undef
  633.      }
  634.     ifelse
  635.     $error /position currentfile status
  636.      { currentfile { fileposition } .internalstopped { pop null } if
  637.      }
  638.      {        % If this was a scanner error, the file is no longer current,
  639.         % but the command holds the file, which may still be open.
  640.        $error /command get dup type /filetype eq
  641.         { { fileposition } .internalstopped { pop null } if }
  642.         { pop null }
  643.        ifelse
  644.      }
  645.     ifelse put
  646.         % During initialization, we don't reset the allocation
  647.         % mode on errors.
  648.     $error /globalmode get $error /.nosetlocal get and .setglobal
  649.     $error /.inerror false put
  650.     stop
  651.   } bind def
  652. % Define the standard handleerror.  We break out the printing procedure
  653. % (.printerror) so that it can be extended for binary output
  654. % if the Level 2 facilities are present.
  655.   /.printerror
  656.    { $error begin
  657.        /command load errorname SHORTERRORS
  658.     { (%%[ Error: ) print =only flush
  659.       (; OffendingCommand: ) print =only
  660.       currentdict /errorinfo .knownget
  661.        { (;\nErrorInfo:) print
  662.          dup type /arraytype eq
  663.           { { ( ) print =only } forall }
  664.           { ( ) print =only }
  665.          ifelse
  666.        } if
  667.           ( ]%%\n) print flush
  668.     }
  669.     { (Error: ) print ==only flush
  670.       ( in ) print ==only flush
  671.       currentdict /errorinfo .knownget
  672.        { (\nAdditional information: ) print ==only flush
  673.        } if
  674.       .printerror_long
  675.     }
  676.        ifelse
  677.        .clearerror
  678.      end
  679.      flush
  680.     } bind def     
  681.   /.printerror_long            % long error printout,
  682.                     % $error is on the dict stack
  683.    {    % Push the (anonymous) stack printing procedure.
  684.     %  <heading> <==flag> <override-name> <stackname> proc
  685.        {
  686.      currentdict exch .knownget    % stackname defined in $error?
  687.      {
  688.        4 1 roll            % stack: <stack> <head> <==flag> <over>
  689.        errordict exch .knownget    % overridename defined?
  690.        { 
  691.          exch pop exch pop exec    % call override with <stack>
  692.        }
  693.        { 
  694.          exch print exch        % print heading. stack <==flag> <stack>
  695.          1 index not { (\n) print } if
  696.          { 1 index { (\n    ) } { (   ) } ifelse print
  697.            dup type /dicttype eq
  698.            {
  699.          (--dict:) print
  700.          dup rcheck
  701.           { dup length =only (/) print maxlength =only }
  702.           { pop }
  703.          ifelse
  704.          (--) print
  705.            }
  706.            {
  707.          dup type /stringtype eq 2 index or
  708.          { ===only } { =only } ifelse
  709.            } ifelse
  710.          } forall
  711.          pop
  712.        }
  713.        ifelse            % overridden
  714.      }
  715.      { pop pop pop
  716.      }
  717.      ifelse                % stack known
  718.        }
  719.  
  720.        (\nOperand stack:) OSTACKPRINT /.printostack /ostack 4 index exec
  721.        (\nExecution stack:) ESTACKPRINT /.printestack /estack 4 index exec
  722.        (\nBacktrace:) true /.printbacktrace /backtrace 4 index exec
  723.        (\nDictionary stack:) false /.printdstack /dstack 4 index exec
  724.        (\n) print
  725.        pop    % printing procedure
  726.  
  727.        errorname /VMerror eq
  728.     { (VM status:) print mark vmstatus
  729.       counttomark { ( ) print counttomark -1 roll dup =only } repeat
  730.       cleartomark (\n) print
  731.     } if
  732.  
  733.        .languagelevel 2 ge
  734.     { (Current allocation mode is ) print
  735.       globalmode { (global\n) } { (local\n) } ifelse print
  736.     } if
  737.  
  738.        .oserrno dup 0 ne
  739.     { (Last OS error: ) print
  740.       errorname /VMerror ne
  741.        { dup .oserrorstring { = pop } { = } ifelse }
  742.        { = }
  743.       ifelse
  744.     }
  745.     { pop
  746.     }
  747.        ifelse
  748.  
  749.        position null ne
  750.     { (Current file position is ) print position = }
  751.        if
  752.  
  753.    } bind def
  754. % Define a procedure for clearing the error indication.
  755. /.clearerror
  756.  { $error /newerror false put
  757.    $error /errorinfo .undef
  758.    0 .setoserrno
  759.  } bind def
  760.  
  761. % Define $error.  This must be in local VM.
  762. .currentglobal false .setglobal
  763. /$error 40 dict def        % newerror, errorname, command, errorinfo,
  764.                 % ostack, estack, dstack, recordstacks,
  765.                 % binary, globalmode,
  766.                 % .inerror, .nosetlocal, position,
  767.         % plus extra space for badly designed error handers.
  768. $error begin
  769.   /newerror false def
  770.   /recordstacks true def
  771.   /binary false def
  772.   /globalmode .currentglobal def
  773.   /.inerror false def
  774.   /.nosetlocal true def
  775.   /position null def
  776. end
  777. % Define errordict similarly.  It has one entry per error name,
  778. %   plus handleerror.
  779. /errordict ErrorNames length 1 add dict def
  780. .setglobal        % contents of errordict are global
  781. errordict begin
  782.   ErrorNames
  783.    { mark 1 index systemdict /.errorhandler get /exec load .packtomark cvx def
  784.    } forall
  785. % The handlers for interrupt and timeout are special; there is no
  786. % 'current object', so they push their own name.
  787.    { /interrupt /timeout }
  788.    { mark 1 index dup systemdict /.errorhandler get /exec load .packtomark cvx def
  789.    } forall
  790. /handleerror
  791.  { //systemdict /.printerror get exec
  792.  } bind def
  793. end
  794.  
  795. % Define the [write]==[only] procedures.
  796. /.dict 26 dict dup
  797. begin def
  798.   /.cvp {1 index exch .writecvs} bind def
  799.   /.nop {exch pop .p} bind def
  800.   /.p {1 index exch writestring} bind def
  801.   /.p1 {2 index exch writestring} bind def
  802.   /.p2 {3 index exch writestring} bind def
  803.   /.print
  804.     { dup type .dict exch .knownget
  805.        { dup type /stringtype eq { .nop } { exec } ifelse }
  806.        { (-) .p1 type .cvp (-) .p }
  807.       ifelse
  808.     } bind def
  809.   /.pstring
  810.     {  { dup dup 32 lt exch 127 ge or
  811.           { (\\) .p1 2 copy -6 bitshift 48 add write
  812.         2 copy -3 bitshift 7 and 48 add write
  813.         7 and 48 add
  814.           }
  815.           { dup dup -2 and 40 eq exch 92 eq or {(\\) .p1} if
  816.           }
  817.          ifelse 1 index exch write
  818.        }
  819.       forall
  820.     } bind def  
  821.   /booleantype /.cvp load def
  822.   /conditiontype (-condition-) def
  823.   /devicetype (-device-) def
  824.   /dicttype (-dict-) def
  825.   /filetype (-file-) def
  826.   /fonttype (-fontID-) def
  827.   /gstatetype (-gstate-) def
  828.   /integertype /.cvp load def
  829.   /locktype (-lock-) def
  830.   /marktype (-mark-) def
  831.   /nulltype (null) def
  832.   /realtype {1 index exch true .writecvp} bind def
  833.   /savetype (-save-) def
  834.   /nametype
  835.     {dup xcheck not {(/) .p1} if
  836.      1 index exch .writecvs} bind def
  837.   /arraytype
  838.     {dup rcheck
  839.       {() exch dup xcheck
  840.         {({) .p2
  841.          {exch .p1
  842.           1 index exch .print pop ( )} forall
  843.          (})}
  844.         {([) .p2
  845.          {exch .p1
  846.           1 index exch .print pop ( )} forall
  847.          (])}
  848.        ifelse exch pop .p}
  849.       {(-array-) .nop}
  850.      ifelse} bind def
  851.   /operatortype
  852.       {(--) .p1 .cvp (--) .p} bind def
  853.   /packedarraytype
  854.     { dup rcheck
  855.        { arraytype }
  856.        { (-packedarray-) .nop }
  857.       ifelse
  858.     } bind def
  859.   /stringtype
  860.     { dup rcheck
  861.        { (\() .p1 dup length 200 le
  862.           { .pstring }
  863.           { 0 200 getinterval .pstring (...) .p }
  864.          ifelse (\)) .p
  865.        }
  866.        { (-string-) .nop
  867.        }
  868.       ifelse
  869.     } bind def
  870. {//.dict begin .print pop end}
  871.   bind
  872. end
  873.  
  874. /write==only exch def
  875. /write== {1 index exch write==only (\n) writestring} bind def
  876. /==only { (%stdout) (w) file exch write==only } bind def
  877. /== {==only (\n) print} bind def
  878.  
  879. % Define [write]===[only], an extension that prints dictionaries
  880. % in readable form and doesn't truncate strings.
  881. /.dict /write==only load 0 get dup length dict .copydict dup
  882. begin def
  883.   /dicttype
  884.     { dup rcheck
  885.        { (<< ) .p1
  886.           { 2 index 3 -1 roll .print pop ( ) .p1
  887.         1 index exch .print pop ( ) .p
  888.           }
  889.          forall (>>) .p
  890.        }
  891.        { (-dict-) .nop
  892.        }
  893.       ifelse
  894.     } bind def
  895.   /stringtype
  896.     { dup rcheck
  897.        { (\() .p1 .pstring (\)) .p }
  898.        { (-string-) .nop }
  899.       ifelse
  900.     } bind def
  901.  
  902. {//.dict begin .print pop end}
  903.   bind
  904. end
  905.  
  906. /write===only exch def
  907. /write=== {1 index exch write===only (\n) writestring} bind def
  908. /===only { (%stdout) (w) file exch write===only } bind def
  909. /=== { ===only (\n) print } bind def
  910.  
  911. (END PROCS) VMDEBUG
  912.  
  913. % Define the font directory.
  914. /FontDirectory false .setglobal 100 dict true .setglobal def
  915.  
  916. % Define the encoding dictionary.
  917. /EncodingDirectory 10 dict def    % enough for Level 2 + PDF standard encodings
  918.  
  919. % Define .findencoding.  (This is redefined in Level 2.)
  920. /.findencoding
  921.  { //EncodingDirectory exch get exec
  922.  } bind def
  923. /.defineencoding
  924.  { //EncodingDirectory 3 1 roll put
  925.  } bind def
  926. % If we've got the composite font extensions, define findencoding.
  927. /rootfont where { pop /findencoding { .findencoding } odef } if
  928.  
  929. % Load StandardEncoding.
  930. %% Replace 1 (gs_std_e.ps)
  931. (gs_std_e.ps) dup runlibfile VMDEBUG
  932.  
  933. % Load ISOLatin1Encoding.
  934. %% Replace 1 (gs_iso_e.ps)
  935. (gs_iso_e.ps) dup runlibfile VMDEBUG
  936.  
  937. % Define stubs for the Symbol and Dingbats encodings.
  938. % Note that the first element of the procedure must be the file name,
  939. % since gs_lev2.ps extracts it to set up the Encoding resource category.
  940.  
  941.   /SymbolEncoding { /SymbolEncoding .findencoding } bind def
  942. %% Replace 3 (gs_sym_e.ps)
  943.   EncodingDirectory /SymbolEncoding
  944.    { (gs_sym_e.ps) //systemdict begin runlibfile SymbolEncoding end }
  945.   bind put
  946.  
  947.   /DingbatsEncoding { /DingbatsEncoding .findencoding } bind def
  948. %% Replace 3 (gs_dbt_e.ps)
  949.   EncodingDirectory /DingbatsEncoding
  950.    { (gs_dbt_e.ps) //systemdict begin runlibfile DingbatsEncoding end }
  951.   bind put
  952.  
  953. (END FONTDIR/ENCS) VMDEBUG
  954.  
  955. % Construct a dictionary of all available devices.
  956. % These are (read-only) device prototypes that can't be
  957. % installed or have their parameters changed.  For this reason,
  958. % the value in the dictionary is actually a 2-element writable array,
  959. % to allow us to create a default instance of the prototype on demand.
  960.  
  961.     % Loop until the .getdevice gets a rangecheck.
  962. errordict /rangecheck 2 copy get
  963. errordict /rangecheck { pop stop } put    % pop the command
  964.   0 { {dup .getdevice exch 1 add} loop} .internalstopped pop
  965.   1 add dict  /devicedict 1 index def
  966.   begin            % 2nd copy of count is on stack
  967.    { dup .devicename exch
  968.      dup wcheck { dup } { null } ifelse 2 array astore def
  969.    } repeat
  970.   end
  971. put        % errordict /rangecheck
  972. .clearerror
  973. /devicenames devicedict { pop } forall devicedict length packedarray def
  974.  
  975. % Determine the default device.
  976. /defaultdevice DISPLAYING
  977.  { systemdict /DEVICE .knownget
  978.     { devicedict 1 index known not
  979.        { (Unknown device: ) print =
  980.      flush /defaultdevice cvx 1 .quit
  981.        }
  982.       if
  983.     }
  984.     { 0 .getdevice .devicename
  985.     }
  986.    ifelse
  987.  }
  988.  { /nullpage
  989.  }
  990. ifelse
  991. /.defaultdevicename 1 index def
  992. finddevice    % make a copy
  993. def
  994. devicedict /Default devicedict .defaultdevicename get put
  995.  
  996. (END DEVS) VMDEBUG
  997.  
  998. % Define statusdict, for the benefit of programs
  999. % that think they are running on a LaserWriter or similar printer.
  1000. %% Replace 1 (gs_statd.ps)
  1001. (gs_statd.ps) runlibfile
  1002.  
  1003. (END STATD) VMDEBUG
  1004.  
  1005. % Load the standard font environment.
  1006. %% Replace 1 (gs_fonts.ps)
  1007. (gs_fonts.ps) runlibfile
  1008.  
  1009. (END GS_FONTS) VMDEBUG
  1010.  
  1011. % Load the initialization files for optional features.
  1012. %% Replace 4 INITFILES
  1013. systemdict /INITFILES known
  1014.  { INITFILES { dup runlibfile VMDEBUG } forall
  1015.  }
  1016. if
  1017.  
  1018. % If Level 2 functionality is implemented, enable it now.
  1019. /.setlanguagelevel where
  1020.  { pop 2 .setlanguagelevel
  1021.     % If the resource machinery is loaded, fix up some things now.
  1022.    /.fixresources where { pop .fixresources } if
  1023.  } if
  1024.  
  1025. (END INITFILES) VMDEBUG
  1026.  
  1027. % Create a null font.  This is the initial font.
  1028. 8 dict dup begin
  1029.   /FontMatrix [ 1 0 0 1 0 0 ] readonly def
  1030.   /FontType 3 def
  1031.   /FontName () def
  1032.   /Encoding StandardEncoding def
  1033.   /FontBBox { 0 0 0 0 } readonly def % executable is bogus, but customary ...
  1034.   /BuildChar { pop pop 0 0 setcharwidth } bind def
  1035.   /PaintType 0 def        % shouldn't be needed!
  1036. end
  1037. /NullFont exch definefont setfont
  1038.  
  1039. % Define NullFont as the font.
  1040. /NullFont currentfont def
  1041.  
  1042. % Load initial fonts from FONTPATH directories, Fontmap file,
  1043. % and/or .getccfont as appropriate.
  1044. .loadinitialfonts
  1045.  
  1046. % Remove NullFont from FontDirectory, so it can't be accessed by mistake.
  1047. FontDirectory /NullFont .undef
  1048.  
  1049. (END FONTS) VMDEBUG
  1050.  
  1051. % Restore the real definition of runlibfile.
  1052. /runlibfile /.runlibfile load def
  1053. currentdict /.runlibfile .undef
  1054.  
  1055. % Bind all the operators defined as procedures.
  1056. /.bindoperators        % binds operators in currentdict
  1057.  { % Temporarily disable the typecheck error.
  1058.    errordict /typecheck 2 copy get
  1059.    errordict /typecheck { pop } put    % pop the command
  1060.    currentdict
  1061.     { dup type /operatortype eq
  1062.        { % This might be a real operator, so bind might cause a typecheck,
  1063.      % but we've made the error a no-op temporarily.
  1064.      .bind        % do a real bind even if NOBIND is set
  1065.        }
  1066.       if pop pop
  1067.     } forall
  1068.    put
  1069.  } def
  1070. NOBIND DELAYBIND or not { .bindoperators } if
  1071.  
  1072. % Establish a default environment.
  1073.  
  1074. defaultdevice
  1075. DISPLAYING not { setdevice (%END DISPLAYING) .skipeof } if
  1076. systemdict /DEVICEWIDTH known
  1077. systemdict /DEVICEHEIGHT known or
  1078. systemdict /DEVICEWIDTHPOINTS known or
  1079. systemdict /DEVICEHEIGHTPOINTS known or
  1080. systemdict /DEVICEXRESOLUTION known or
  1081. systemdict /DEVICEYRESOLUTION known or
  1082. systemdict /PAPERSIZE known or
  1083. not { (%END DEVICE) .skipeof } if
  1084. % Let DEVICE{WIDTH,HEIGHT}[POINTS] override PAPERSIZE.
  1085. systemdict /PAPERSIZE known
  1086. systemdict /DEVICEWIDTH known not and
  1087. systemdict /DEVICEHEIGHT known not and
  1088. systemdict /DEVICEWIDTHPOINTS known not and
  1089. systemdict /DEVICEHEIGHTPOINTS known not and
  1090.  {    % Convert the paper size to device dimensions.
  1091.    true statusdict /.pagetypenames get
  1092.     { PAPERSIZE eq
  1093.        { PAPERSIZE load
  1094.          dup 0 get /DEVICEWIDTHPOINTS exch def
  1095.          1 get /DEVICEHEIGHTPOINTS exch def
  1096.          pop false exit
  1097.        }
  1098.       if
  1099.     }
  1100.    forall
  1101.     { (Unknown paper size: ) print PAPERSIZE ==only (.\n) print
  1102.     }
  1103.    if
  1104.  }
  1105. if
  1106. % Adjust the device parameters per the command line.
  1107. % It is possible to specify resolution, pixel size, and page size;
  1108. % since any two of these determine the third, conflicts are possible.
  1109. % We simply pass them to .setdeviceparams and let it sort things out.
  1110.    mark /HWResolution null /HWSize null /PageSize null .dicttomark
  1111.    .getdeviceparams .dicttomark begin
  1112.    mark
  1113.     % Check for resolution.
  1114.    /DEVICEXRESOLUTION where dup
  1115.     { exch pop HWResolution 0 DEVICEXRESOLUTION put }
  1116.    if
  1117.    /DEVICEYRESOLUTION where dup
  1118.     { exch pop HWResolution 1 DEVICEYRESOLUTION put }
  1119.    if
  1120.    or { /HWResolution HWResolution } if
  1121.     % Check for device sizes specified in pixels.
  1122.    /DEVICEWIDTH where dup
  1123.     { exch pop HWSize 0 DEVICEWIDTH put }
  1124.    if
  1125.    /DEVICEHEIGHT where dup
  1126.     { exch pop HWSize 1 DEVICEHEIGHT put }
  1127.    if
  1128.    or { /HWSize HWSize } if
  1129.     % Check for device sizes specified in points.
  1130.    /DEVICEWIDTHPOINTS where dup
  1131.     { exch pop PageSize 0 DEVICEWIDTHPOINTS put }
  1132.    if
  1133.    /DEVICEHEIGHTPOINTS where dup
  1134.     { exch pop PageSize 1 DEVICEHEIGHTPOINTS put }
  1135.    if
  1136.    or { /PageSize PageSize } if
  1137.     % Check whether any parameters were set.
  1138.    dup mark eq { pop } { defaultdevice putdeviceprops } ifelse
  1139.    end
  1140. %END DEVICE
  1141. % Set any device properties defined on the command line.
  1142. % If BufferSpace is defined but not MaxBitmap, set MaxBitmap to BufferSpace.
  1143. systemdict /BufferSpace known
  1144. systemdict /MaxBitmap known not and
  1145.  { systemdict /MaxBitmap BufferSpace put
  1146.  } if
  1147. dup getdeviceprops
  1148. counttomark 2 idiv
  1149.  { systemdict 2 index known
  1150.     { pop dup load counttomark 2 roll }
  1151.     { pop pop }
  1152.    ifelse
  1153.  } repeat
  1154. counttomark dup 0 ne
  1155.  { 2 add -1 roll putdeviceprops }
  1156.  { pop pop }
  1157. ifelse
  1158. setdevice        % does an erasepage
  1159. % If the media size is fixed, update the current page device dictionary.
  1160. FIXEDMEDIA
  1161. dup { pop systemdict /.currentpagedevice known } if
  1162. dup { pop .currentpagedevice exch pop } if
  1163. not { (%END MEDIA) .skipeof } if
  1164. currentpagedevice dup length dict .copydict
  1165. dup /Policies
  1166.     % Stack: <pagedevice> <pagedevice> /Policies
  1167. 1 index /InputAttributes
  1168. 2 copy get dup length dict .copydict
  1169.     % Stack: <pagedevice> <pagedevice> /Policies <pagedevice>
  1170.     %   /InputAttributes <inputattrs'>
  1171. dup 0 2 copy get dup length dict .copydict
  1172.     % Stack: <pagedevice> <pagedevice> /Policies <pagedevice>
  1173.     %   /InputAttributes <inputattrs'> <inputattrs'> 0 <attrs0'>
  1174. dup /PageSize 7 index /PageSize get
  1175. put                % PageSize in 0
  1176. put                % 0 in InputAttributes
  1177. put                % InputAttributes in pagedevice
  1178. % Also change the page size policy so we don't get an error.
  1179.     % Stack: <pagedevice> <pagedevice> /Policies
  1180. 2 copy get dup length dict .copydict
  1181.     % Stack: <pagedevice> <pagedevice> /Policies <policies'>
  1182. dup /PageSize 7 put        % PageSize in Policies
  1183. put                % Policies in pagedevice
  1184. .setpagedevice
  1185. %END MEDIA
  1186. %END DISPLAYING
  1187.  
  1188. (END DEVICE) VMDEBUG
  1189.  
  1190. % Establish a default upper limit in the character cache,
  1191. % namely, enough room for a 18-point character at the resolution
  1192. % of the default device, or for a character consuming 1% of the
  1193. % maximum cache size, whichever is larger.
  1194. mark
  1195.     % Compute limit based on character size.
  1196.   18 dup dtransform
  1197.   exch abs cvi 31 add 32 idiv 4 mul    % X raster
  1198.   exch abs cvi mul        % Y
  1199.     % Compute limit based on allocated space.
  1200.   cachestatus pop pop pop pop pop exch pop 0.01 mul cvi
  1201.   .max dup 10 idiv exch
  1202. setcacheparams
  1203. % Conditionally disable the character cache.
  1204. NOCACHE { 0 setcachelimit } if
  1205.  
  1206. (END CONFIG) VMDEBUG
  1207.  
  1208. % Establish an appropriate halftone screen and BG/UCR functions.
  1209. % We make this a procedure so we can call it again when switching devices.
  1210.  
  1211. % Use an ordered dither for low-resolution devices.
  1212. /.setloresscreen    % <dpi> .setloresscreen -
  1213.  {    % The following 'ordered dither' spot function was contributed by
  1214.     % Gregg Townsend.  Thanks, Gregg!
  1215.    16.001 div 0            % not 16: avoids rounding problems
  1216.     { 1 add 7.9999 mul cvi exch 1 add 7.9999 mul cvi 16 mul add <
  1217.     0E 8E 2E AE 06 86 26 A6 0C 8C 2C AC 04 84 24 A4
  1218.     CE 4E EE 6E C6 46 E6 66 CC 4C EC 6C C4 44 E4 64
  1219.     3E BE 1E 9E 36 B6 16 96 3C BC 1C 9C 34 B4 14 94
  1220.     FE 7E DE 5E F6 76 D6 56 FC 7C DC 5C F4 74 D4 54
  1221.     01 81 21 A1 09 89 29 A9 03 83 23 A3 0B 8B 2B AB
  1222.     C1 41 E1 61 C9 49 E9 69 C3 43 E3 63 CB 4B EB 6B
  1223.     31 B1 11 91 39 B9 19 99 33 B3 13 93 3B BB 1B 9B
  1224.     F1 71 D1 51 F9 79 D9 59 F3 73 D3 53 FB 7B DB 5B
  1225.     0D 8D 2D AD 05 85 25 A5 0F 8F 2F AF 07 87 27 A7
  1226.     CD 4D ED 6D C5 45 E5 65 CF 4F EF 6F C7 47 E7 67
  1227.     3D BD 1D 9D 35 B5 15 95 3F BF 1F 9F 37 B7 17 97
  1228.     FD 7D DD 5D F5 75 D5 55 FF 7F DF 5F F7 77 D7 57
  1229.     02 82 22 A2 0A 8A 2A AA 00 80 20 A0 08 88 28 A8
  1230.     C2 42 E2 62 CA 4A EA 6A C0 40 E0 60 C8 48 E8 68
  1231.     32 B2 12 92 3A BA 1A 9A 30 B0 10 90 38 B8 18 98
  1232.     F2 72 D2 52 FA 7A DA 5A F0 70 D0 50 F8 78 D8 58
  1233.      > exch get 256 div
  1234.     }
  1235.    bind
  1236.         % Use correct, per-plane screens for CMYK devices only.
  1237.    //systemdict /setcolorscreen known processcolors 4 eq and
  1238.     { 3 copy 6 copy setcolorscreen }
  1239.     { setscreen }
  1240.    ifelse
  1241.    0 array cvx settransfer    % Genoa CET won't accept a packed array!
  1242.    /setstrokeadjust where { pop true setstrokeadjust } if
  1243.  } bind def
  1244. % Use a 45-degree spot screen for high-resolution devices.
  1245. /.sethiresscreen    % <dpi> .sethiresscreen -
  1246.  {    % According to information published by Hewlett-Packard,
  1247.     % they use a 60 line screen on 300 DPI printers and
  1248.     % an 85 line screen on 600 DPI printers.
  1249.     % 46 was suggested as a good frequency value for printers
  1250.     % between 200 and 400 DPI, so we use it for lower resolutions.
  1251.     % Imagesetters need even higher frequency screens.
  1252.    //systemdict /DITHERPPI known
  1253.     { DITHERPPI
  1254.     }
  1255.     { dup cvi 100 idiv 15 .min
  1256.        {null 46 46 60 60 60 85 100 100 100 133 133 133 133 133 150}
  1257.       exch get
  1258.      }
  1259.    ifelse
  1260.    1 index 4.01 div .min    % at least a 4x4 cell
  1261.    45
  1262.     % The following screen algorithm is used by permission of the author.
  1263.     { 1 add 180 mul cos 1 0.08 add mul exch 2 add 180 mul cos 
  1264.       1 0.08 sub mul add 2 div % (C) 1989 Berthold K.P. Horn
  1265.     }
  1266.    bind
  1267.     % Determine whether we have lots of process colors.
  1268.     % If so, don't bother with color screening or gamma correction.
  1269.     % Also don't do gamma correction on very high-resolution devices.
  1270.     % (This should depend on dot gain, not resolution, but we don't
  1271.     % currently have a way to determine this.)
  1272.    currentdevice mark
  1273.      /RedValues 0 /GreenValues 0 /BlueValues 0 /GrayValues 0
  1274.    .dicttomark .getdeviceparams
  1275.    counttomark 2 idiv 1 sub { exch pop min } repeat
  1276.    exch pop exch pop 32 lt 4 index 800 lt and 5 1 roll
  1277.     % Stack: doscreen dpi freq angle proc
  1278.     % Ghostscript currently doesn't use correct, per-plane halftones
  1279.     % unless setcolorscreen has been executed.  Since these are
  1280.     % computationally much more expensive than binary halftones,
  1281.     % we check to make sure they are really warranted, i.e., we have
  1282.     % a high-resolution CMYK device (i.e., not a display) with
  1283.     % fewer than 5 bits per plane (i.e., not a true-color device).
  1284.    4 -1 roll 150 ge
  1285.     { /setcolorscreen where
  1286.        { pop //systemdict /COLORSCREEN known
  1287.       { COLORSCREEN }
  1288.       { 3 index }
  1289.      ifelse
  1290.      dup false ne
  1291.       { 4 1 roll 3 copy 6 copy 13 -1 roll
  1292.     % For really high-quality screening on printers, we need to
  1293.     % give each plane its own screen angle.  Unfortunately,
  1294.     % this currently has very large space and time costs.
  1295.         true eq        % true => different angles,
  1296.                 % 0 => same angles
  1297.          { { 45 90 15 75 } { 3 1 roll exch pop 12 3 roll } forall
  1298.          }
  1299.         if setcolorscreen
  1300.       }
  1301.       { pop setscreen    % false => single binary screen
  1302.       }
  1303.      ifelse
  1304.        }
  1305.        { setscreen        % setcolorscreen not known
  1306.        }
  1307.       ifelse
  1308.     }
  1309.     { setscreen            % not high resolution
  1310.     }
  1311.    ifelse
  1312.             % Stack: doscreen
  1313.     {    % Set the transfer function to lighten up the grays.
  1314.     % We correct at the high end so that very light grays
  1315.     % don't disappear completely if they darken <1 screen pixel.
  1316.     % Parameter values closer to 1 are better for devices with
  1317.     % less dot spreading; lower values are better with more spreading.
  1318.     % The value 0.8 is a compromise that will probably please no one!
  1319.     %
  1320.     % Because of a bug in FrameMaker, we have to accept operands
  1321.     % outside the valid range of [0..1].
  1322.       { dup dup 0.0 gt exch 1.0 lt and
  1323.      { 0.8 exp dup dup 0.9375 gt exch 0.999 lt and    % > 15/16
  1324.         { .currentscreenlevels 1 sub    % tweak to avoid boundary
  1325.           1 exch div 1 exch sub .min
  1326.         }
  1327.        if
  1328.      }
  1329.     if
  1330.       }
  1331.     }
  1332.     {    % Set the transfer function to the identity.
  1333.       0 array cvx        % Genoa CET won't accept a packed array!
  1334.     }
  1335.    ifelse settransfer
  1336.    /setstrokeadjust where { pop false setstrokeadjust } if
  1337.     % Increase fill adjustment so that we effectively use Adobe's
  1338.     % any-part-of-pixel rule.
  1339.    0.5 .setfilladjust
  1340.  } bind def
  1341. % Set the default screen and BG/UCR based on the device resolution and
  1342. % process color capability.
  1343. /.setdefaultbgucr systemdict /setblackgeneration known { {
  1344.   processcolors 1 eq { { } } { { pop 0.0 } } ifelse
  1345.   dup setblackgeneration setundercolorremoval
  1346. } } { {
  1347. } } ifelse bind def
  1348. /.setdefaultscreen
  1349.  {    % Compute min(|dpi x|,|dpi y|) as the definition of the resolution.
  1350.    72 72 matrix defaultmatrix dtransform abs exch abs .min
  1351.    dup 150 lt //systemdict /DITHERPPI known not and
  1352.     { .setloresscreen } { .sethiresscreen }
  1353.    ifelse .setdefaultbgucr
  1354.  } bind def
  1355. .setdefaultscreen
  1356. initgraphics
  1357.  
  1358. % The interpreter relies on there being at least 2 entries
  1359. % on the graphics stack.  Establish the second one now.
  1360. gsave
  1361.  
  1362. % Define some control sequences as no-ops.
  1363. % This is a hack to get around problems
  1364. % in some common PostScript-generating applications.
  1365. % Note that <04> and <1a> are self-delimiting characters, like [.
  1366. <04> cvn { } def        % Apple job separator
  1367. %<0404> cvn { } def        % two of the same
  1368. <1b> cvn { } def        % MS Windows LaserJet 4 prologue
  1369. %<041b> cvn { } def        % MS Windows LaserJet 4 epilogue
  1370. (\001M) cvn            % TBCP initiator
  1371.  { currentfile /TBCPDecode filter cvx exec
  1372.  } bind def
  1373. /@PJL                % H-P job control
  1374.  { currentfile //=string readline { pop } if
  1375.  } bind def
  1376.  
  1377. % If we want a "safer" system, disable some obvious ways to cause havoc.
  1378. SAFER not { (%END SAFER) .skipeof } if
  1379. /file
  1380.  { dup (r) eq 2 index (%pipe*) .stringmatch not and
  1381.    2 index (%std*) .stringmatch or
  1382.     { file }
  1383.     { /invalidfileaccess signalerror }
  1384.    ifelse
  1385.  } .bind odef
  1386. /renamefile { /invalidfileaccess signalerror } odef
  1387. /deletefile { /invalidfileaccess signalerror } odef
  1388. /putdeviceprops
  1389.  { counttomark
  1390.    dup 2 mod 0 eq { pop /rangecheck signalerror } if
  1391.    3 2 3 2 roll
  1392.     { dup index /OutputFile eq  
  1393.        { -2 roll 
  1394.          dup () ne { /putdeviceprops load /invalidfileaccess signalerror } if
  1395.          3 -1 roll
  1396.        }
  1397.        { pop
  1398.        }
  1399.       ifelse
  1400.     } for
  1401.    putdeviceprops
  1402.  } .bind odef
  1403.  
  1404. %END SAFER
  1405.  
  1406. % If we delayed binding, make it possible to do it later.
  1407. /.bindnow
  1408.  { //systemdict begin .bindoperators end
  1409.    % Temporarily disable the typecheck error.
  1410.    errordict /typecheck 2 copy get
  1411.    errordict /typecheck { pop } put    % pop the command
  1412.    0 1 .delaycount 1 sub { .delaybind exch get .bind pop } for
  1413.    userdict /.delaybind .undef        % reclaim the space
  1414.    userdict /.delaycount .undef
  1415.    put
  1416.  } .bind def
  1417.  
  1418. % Turn off array packing, since some PostScript code assumes that
  1419. % procedures are writable.
  1420. false setpacking
  1421.  
  1422. % Close up systemdict.
  1423. currentdict /.forceput .undef        % remove temptation
  1424. currentdict /filterdict .undef        % bound in where needed
  1425. end
  1426. WRITESYSTEMDICT not { systemdict readonly pop } if
  1427.  
  1428. (END INIT) VMDEBUG
  1429.  
  1430. % Since some badly-behaved files include extremely long procedures,
  1431. % or construct huge arrays on the operand stack, increase the operand
  1432. % stack size here.
  1433. /setuserparams where
  1434.  { pop mark /MaxOpStack 20000 .dicttomark setuserparams
  1435.  } if
  1436.  
  1437. % Establish local VM as the default.
  1438. false /setglobal where { pop setglobal } { .setglobal } ifelse
  1439. $error /.nosetlocal false put
  1440.  
  1441. % Clean up VM, and enable GC.
  1442. /vmreclaim where
  1443.  { pop NOGC not { 2 vmreclaim 0 vmreclaim } if
  1444.  } if
  1445.  
  1446. (END GC) VMDEBUG
  1447.  
  1448. % The interpreter will run the initial procedure (start).
  1449.